import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';

// 导入提供者
import 'package:netflix_social/providers/auth_provider.dart';
import 'package:netflix_social/providers/video_provider.dart';
import 'package:netflix_social/providers/social_provider.dart';

// 导入主题
import 'package:netflix_social/theme/app_theme.dart';

// 导入常量
import 'package:netflix_social/constants/app_constants.dart';

// 导入界面
import 'package:netflix_social/screens/splash_screen.dart';
import 'package:netflix_social/screens/login_screen.dart';
import 'package:netflix_social/screens/main_screen.dart';
import 'package:netflix_social/screens/video_detail_screen.dart';
import 'package:netflix_social/screens/player_screen.dart';
import 'package:netflix_social/screens/notifications_screen.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 设置状态栏为透明
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.light,
    ),
  );
  
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => AuthProvider()),
        ChangeNotifierProvider(create: (_) => VideoProvider()),
        ChangeNotifierProvider(create: (_) => SocialProvider()),
      ],
      child: Consumer<AuthProvider>(
        builder: (context, authProvider, _) {
          return MaterialApp(
            title: AppConstants.appName,
            debugShowCheckedModeBanner: false,
            theme: AppTheme.darkTheme,
            initialRoute: '/',
            routes: {
              '/': (context) => const SplashScreen(),
              AppConstants.loginRoute: (context) => const LoginScreen(),
              AppConstants.homeRoute: (context) => const MainScreen(initialTabIndex: 0),
              AppConstants.exploreRoute: (context) => const MainScreen(initialTabIndex: 1),
              AppConstants.socialRoute: (context) => const MainScreen(initialTabIndex: 2),
              AppConstants.profileRoute: (context) => const MainScreen(initialTabIndex: 4),
              AppConstants.notificationsRoute: (context) => const NotificationsScreen(),
            },
            onGenerateRoute: (settings) {
              if (settings.name == AppConstants.videoDetailRoute) {
                final videoId = settings.arguments as String;
                return MaterialPageRoute(
                  builder: (context) => VideoDetailScreen(videoId: videoId),
                );
              } else if (settings.name == AppConstants.playerRoute) {
                final videoId = settings.arguments as String;
                return MaterialPageRoute(
                  builder: (context) => PlayerScreen(videoId: videoId),
                );
              }
              return null;
            },
          );
        },
      ),
    );
  }
}
